package com.lemon.smartsafetynew.net.services;

import android.content.Context;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.http.service.BaseHttpServices;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenDownloadVo;
import com.lemon.smartsafetynew.entity.incident.IncidentSafePatrolChildItemVo;
import com.lemon.smartsafetynew.entity.incident.IncidentVo;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;

/**
 * Created by Andrew on 2017/9/11.
 */

public class IncidentServices extends BaseHttpServices {

    public static final String TAG = "IncidentServices";

    public IncidentServices(Context context) {
        super(context);
    }

    /**
     * 初始化，等同使用构造函数
     *
     * @return
     */
    public static IncidentServices init() {
        return new IncidentServices(IApplication.context());
    }


    /**
     * 初始化，等同使用构造函数
     *
     * @param context
     * @return
     */
    public static IncidentServices init(Context context) {
        return new IncidentServices(context);
    }



    /**
     * 获取安全巡查任务列表
     *
     * @param type
     * @param params
     * @param status { ("0", "待处理"), ("1", "已处理")}
     */
    public void getIncidentList(RefreshType type, LemonRequestParams params, String status) {

        HandlerCallback<List<IncidentVo>> callback = new HandlerCallback<List<IncidentVo>>(KeyConstants.URL_GET_INCIDENT_LIST + status) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_INCIDENT_LIST, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }

    /**
     * 获取安全巡查事件详情
     * @param params
     */
    public void getIncidentDetail(LemonRequestParams params) {

        HandlerCallback<IncidentSafePatrolChildItemVo> callback = new HandlerCallback<IncidentSafePatrolChildItemVo>(KeyConstants.URL_GET_INCIDENT_SAFE_PATROL_DETAIL) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_INCIDENT_SAFE_PATROL_DETAIL, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }

    /**
     * 关闭安全巡查事件
     * @param params
     */
    public void postCloseIncident(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_POST_CLOSE_SAFE_PATROL_INCIDENT) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.POST_CLOSE_SAFE_PATROL_INCIDENT, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }


    /**
     * 安全巡查事件升级为隐患
     * @param params
     */
    public void postUpIncidentToHidden(LemonRequestParams params) {

        HandlerCallback<String> callback = new HandlerCallback<String>(KeyConstants.URL_POST_UP_SAFE_PATROL_INCIDENT_TO_HIDDEN) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.POST_UP_SAFE_PATROL_INCIDENT_TO_HIDDEN, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }

    /**
     * 获取隐患事件的处理历史
     * @param params
     */
    public void getIncidentHandleHistory(LemonRequestParams params) {

        HandlerCallback<SafeHiddenDownloadVo> callback = new HandlerCallback<SafeHiddenDownloadVo>(KeyConstants.URL_GET_INCIDENT_HANDLE_HISTORY) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_INCIDENT_HANDLE_HISTORY, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }

}
